package com.hzb.shop.manager.conf;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Administrator on 2017/9/11.
 */
public class Config {
      private static Map<String,String> map = new ConcurrentHashMap<String,String>();

      //根据Key读取Value
      public static String GetValueByKey( String key) {
          String str = map.get(key);
          if(null!=str){
              return str;
          }
         Properties pps = new Properties();
         try {
             InputStream in = new BufferedInputStream(new FileInputStream(Config.class.getClassLoader().getResource("config.properties").getFile()));
             pps.load(in);
             String value = pps.getProperty(key);
             System.out.println(key + " = " + value);
             return value;
         }catch (IOException e) {
             e.printStackTrace();
             return null;
         }
      }
      public static String getRootPath(){
          return GetValueByKey("root.path");
      }
      public static void main(String[] args){
          GetValueByKey("root.path");
      }
}
